
import json
from config import BaseDir
from uitls.dbutil import DBUtil
from xml.dom import minidom
import xlrd

class bulid_data:

    def bulid_data_json(self):
        json_file = BaseDir+"/data/weather_forcast.json"
        test_data = []
        with open(json_file,encoding="utf-8") as f :
            josn_data = json.load(f)
            print(josn_data)
            for case_data in josn_data :
                city = case_data.get("city")
                key = case_data.get("key")
                test_data.append((city,key))
            print(test_data)
        return test_data


    def bulid_data_db(self):
        sql = "select * from laohuangli"
        db_data = DBUtil.exe_sql(sql)
        print(db_data)
        test_data = []
        for case_data in db_data:
            key = case_data[0]
            date = case_data[1]
            reason =case_data[2]
            error_code = case_data[3]
            test_data.append((key, date, reason, error_code))
            # print("test_data = {}".format(test_data))
        return test_data


    def read_xml(self,filename,onenode,twonode):
        root = minidom.parse(filename)
        fristnode = root.getElementsByTagName(onenode)[0]
        secondnode = fristnode.getElementsByTagName(twonode)[0].firstChild.data

        return secondnode




if __name__ == '__main__':

    url = bulid_data().read_xml("E:\Pycharm\InterfaceTest\data\data_weather.xml","weather","url")
    print(url)